import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import SearchView from '../views/SearchView.vue'
import ClassView from '../views/ClassView.vue'
import MyView from '../views/MyView.vue'
import MainNavView from '../views/MainNavView.vue'
import DetailView from '../views/DetailView.vue'
import LoginView from '../views/LoginView.vue'
import WorksView from '../views/WorksView.vue'
import SearchPageView from '../views/SearchPageView.vue'
import FollowView from '../views/FollowView.vue'
import UserinfoView from '../views/UserinfoView.vue'


const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'mainnav',
      component: MainNavView,
      children: [
        {
          path: '',
          name: 'home',
          component: HomeView
        },
        {
          path: 'search',
          name: 'search',
          component: SearchView
        },
        {
          path: 'class',
          name: 'class',
          component: ClassView
        },
        {
          path: 'my',
          name: 'my',
          component: MyView
        },]
    },
    {
      path: '/detail',
      name: 'detail',
      component: DetailView
    },
    {
      path: '/login',
      name: 'login',
      component: LoginView
    },
    {
      path: '/works',
      name: 'works',
      component: WorksView
    },
    {
      path: '/searchpage',
      name: 'searchpage',
      component: SearchPageView
    },
    {
      path: '/follow',
      name: 'follow',
      component: FollowView
    },
    {
      path: '/userinfo',
      name: 'userinfo',
      component: UserinfoView
    },

    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (About.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import('../views/AboutView.vue')
    // }
  ],

  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {

      return savedPosition
    } else {

      return { left: 0, top: 0 };
    }
  }


})

export default router
